package com.io;

import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;

public class EchoMutilHandle implements Runnable{

    private Socket client;

    public EchoMutilHandle(Socket client) {
        this.client = client;
    }

    @Override
    public void run() {

        try {
            Scanner scanner = new Scanner(client.getInputStream());
            PrintStream out = new PrintStream(client.getOutputStream());
            boolean flag = true;
            while (flag) {
                if (scanner.hasNext()) {
                    String value = scanner.next().trim();
                    if (value.equalsIgnoreCase("exit")) {
                        out.println("服务器：信息服务交互完成，已经断开与服务器的连接");
                        flag = false;
                        break;
                    }
                    out.println("ECHO: " + value);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
